﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using SimpleFMMatrix.DataStructures;

namespace SimpleFMMatrix.ViewModel
{
    public class PianoKey
    {
        public static readonly IEnumerable<PianoKey> AllKeys;

        static PianoKey()
        {
            Func<int, bool> CalcIsBlackKey = i =>
            {
                switch (i % 12)
                {
                    case 0:
                    case 2:
                    case 4:
                    case 5:
                    case 7:
                    case 9:
                    case 11:
                        return false;

                    case 1:
                    case 3:
                    case 6:
                    case 8:
                    case 10:
                        return true;

                    default:
                        throw new Exception("LOL WUT");
                }
            };

            Func<int, double> CalcXShift = i =>
            {
                if (i == 22)
                    return 0;

                switch (i % 12)
                {
                    case 1:
                        return -1;
                    case 3:
                        return 1;
                    case 6:
                        return -2;
                    case 10:
                        return 2;
                    default:
                        return 0;
                }
            };

            AllKeys = new object[88]
                .Select((o, i) => i + 21)
                .Select(i => new PianoKey(CalcIsBlackKey(i), i, CalcXShift(i), CalcIsBlackKey(i) ? 1 : 0))
                .ToList();
        }

        public bool IsBlackKey { get; private set; }
        public int MidiNumber { get; private set; }
        public double DisplayXShift { get; private set; }
        public int DisplayZIndex { get; private set; }

        private PianoKey(bool _IsBlackKey, int _MidiNumber, double _DisplayXShift, int _DisplayZIndex)
        {
            IsBlackKey = _IsBlackKey;
            MidiNumber = _MidiNumber;
            DisplayXShift = _DisplayXShift;
            DisplayZIndex = _DisplayZIndex;
        }
    }
}
